package com.nbsaas.boot.entity.evaluate;


import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.bean.StoreStateBean;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.util.Date;

@Comment("通用评价功能")
@FormAnnotation(title = "评价管理", model = "评价", menu = "1,70,71", searchWidth = "100", viewWidth = "120")
@StoreStateBean
@CreateByUser
@ComposeView
@Data
@Entity
@Table(name = "bs_evaluate")
public class Evaluate extends AbstractEntity {

    @Comment("评价创建者")
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;


    private String name;

    @Comment("被评价用户")
    @SearchItem(label = "被评价用户", name = "targetUser", key = "targetUser.id", operator = Operator.eq, classType = Long.class)
    @FormField(title = "被评价用户", sortNum = "10", grid = true, type = InputType.select, option = "user")
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User targetUser;

    @Comment("评价分类")
    @SearchItem(label = "评价分类", name = "catalog", key = "catalog.id", operator = Operator.eq, classType = Long.class)
    @FormField(title = "评价分类", sortNum = "15", grid = true, type = InputType.tree, option = "evaluateCatalog")
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private EvaluateCatalog catalog;

    @Comment("评价分数")
    @SearchItem(label = "评价分数", name = "score", operator = Operator.eq, classType = Integer.class)
    @FormField(title = "评价分数", sortNum = "20", grid = true, required = true, type = InputType.el_input_number)
    @Column(nullable = false)
    private Integer score;

    @Comment("评价类型")
    @SearchItem(label = "评价类型", name = "evaluateType", operator = Operator.eq, classType = Integer.class, type = InputType.dictionary)
    @FormField(title = "评价类型", sortNum = "30", grid = true, type = InputType.dictionary)
    @Dict(
            items = {
                    @DictItem(value = 1, label = "商品评价"),
                    @DictItem(value = 2, label = "服务评价"),
                    @DictItem(value = 3, label = "用户评价"),
                    @DictItem(value = 4, label = "文章评价"),
                    @DictItem(value = 5, label = "其他评价")
            }
    )
    private Integer evaluateType;

    @Comment("业务对象ID")
    @FormField(title = "业务对象ID", sortNum = "40", grid = true, type = InputType.el_input_number)
    private Long businessId;

    @Comment("业务对象类型")
    @FormField(title = "业务对象类型", sortNum = "50", grid = true)
    @Column(length = 50)
    private String businessType;

    @Comment("评价标题")
    @SearchItem(label = "评价标题", name = "title", operator = Operator.like)
    @FormField(title = "评价标题", sortNum = "60", grid = true)
    @Column(length = 200)
    private String title;

    @Comment("评价内容")
    @FormField(title = "评价内容", sortNum = "70", grid = true, type = InputType.textarea, col = 23)
    @Column(length = 2000)
    private String note;


    @Comment("是否匿名")
    @SearchItem(label = "是否匿名", name = "anonymous", operator = Operator.eq, classType = Integer.class, type = InputType.dictionary)
    @FormField(title = "是否匿名", sortNum = "90", grid = true, type = InputType.dictionary)
    @Dict(
            items = {
                    @DictItem(value = 0, label = "否"),
                    @DictItem(value = 1, label = "是")
            }
    )
    private Integer anonymous;

    @Comment("回复内容")
    @FormField(title = "回复内容", sortNum = "100", grid = true, type = InputType.textarea, col = 23)
    @Column(length = 1000)
    private String replyContent;

    @Comment("回复时间")
    @FormField(title = "回复时间", sortNum = "110", grid = true, type = InputType.el_date_time_picker, width = "160")
    private Date replyDate;

    @Comment("回复用户")
    @FormField(title = "回复用户", sortNum = "120", grid = true, type = InputType.select, option = "user")
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User replyUser;

    @Comment("有用数量")
    @FormField(title = "有用数量", sortNum = "130", grid = true, type = InputType.el_input_number, sort = true)
    private Integer helpfulCount;

    @Comment("无用数量")
    @FormField(title = "无用数量", sortNum = "140", grid = true, type = InputType.el_input_number, sort = true)
    private Integer unhelpfulCount;

    @Comment("评价标签")
    @FormField(title = "评价标签", sortNum = "150", grid = true)
    @Column(length = 500)
    private String tags;

    @Comment("评价状态")
    @SearchItem(name = "storeState", label = "状态", operator = Operator.eq, classType = StoreState.class)
    @FormField(title = "状态", sortNum = "160", grid = true, type = InputType.dictionary)
    private StoreState storeState;

    @Comment("审核备注")
    @FormField(title = "审核备注", sortNum = "170", grid = true, type = InputType.textarea)
    @Column(length = 500)
    private String auditNote;

    @Comment("审核时间")
    @FormField(title = "审核时间", sortNum = "180", grid = true, type = InputType.el_date_time_picker, width = "160")
    private Date auditDate;

    @Comment("审核用户")
    @FormField(title = "审核用户", sortNum = "190", grid = true, type = InputType.select, option = "user")
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User auditUser;

}
